Skip to content

Conversation

@tzolov
Copy link
Contributor

@tzolov tzolov commented Nov 23, 2024

  • Introduces a new FunctionCallbackResolver interface to define the strategy for resolving FunctionCallback instances from the application context.
  • Renames FunctionCallbackContext to DefaultFunctionCallbackResolver to better reflect its implementation role. Updates all related components to use the new interface.
  • Update the affected AI model implementations
    • Replaces FunctionCallbackContext parameter with FunctionCallbackResolver in all model constructors
    • Updates builder patterns to use functionCallbackResolver() method instead of withFunctionCallbackContext()
    • Deprecates old withFunctionCallbackContext() methods in builders to guide migration
  • Updates integration tests to use DefaultFunctionCallbackResolver
  • Improves documentation to clarify the resolver's role in function callbacks
  • Moves SchemaType enum from FunctionCallbackContext to FunctionCallback (Braking change)git add .

Resolves #758

@tzolov tzolov added this to the 1.0.0-M5 milestone Nov 23, 2024
@tzolov tzolov mentioned this pull request Nov 23, 2024
10 tasks
* @param functionCallbackContext the function callback context used to store the
* state of the function calls.
* @param functionCallbackResolver the function callback resolver used to resolve the
* function by bean name.s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

* Moonshot Chat API.
* @param options The MoonshotChatOptions to configure the chat client.
* @param functionCallbackContext The function callback context.
* @param functionCallbackResolver The function callback resolver to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc sentence incomplete.

* Chat API.
* @param options The OpenAiChatOptions to configure the chat model.
* @param functionCallbackContext The function callback context.
* @param functionCallbackResolver The function callback context.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc still refers to callback context.


var chatTypes = Set.of(AbstractMessage.class, AssistantMessage.class, ToolResponseMessage.class, Message.class,
MessageType.class, UserMessage.class, SystemMessage.class, FunctionCallbackContext.class,
MessageType.class, UserMessage.class, SystemMessage.class, DefaultFunctionCallbackResolver.class,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work when we have other implementations of "FunctionCallbackResolver"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are other implementation they have to be added here.

else {
throw new IllegalStateException(
"No function callback [" + functionName + "] fund in tht FunctionCallbackContext");
"No function callback [" + functionName + "] fund in tht FunctionCallbackRegister");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in the exception message.

import org.springframework.lang.Nullable;

/**
* Strategy interface for resolving {@link FunctionCallback} instances as bean from the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there could be an implementation for the FunctionCallbackResolver that doesn't depend on the application context, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not think of any not app context case?

- Introduces a new FunctionCallbackResolver interface to define the strategy for
  resolving FunctionCallback instances from the application context.
- Renames FunctionCallbackContext to DefaultFunctionCallbackResolver to better reflect its
  implementation role. Updates all related components to use the new interface.
- Update the affected AI model implementations
  - Replaces FunctionCallbackContext parameter with FunctionCallbackResolver in all
    model constructors
  - Updates builder patterns to use functionCallbackResolver() method instead of
    withFunctionCallbackContext()
  - Deprecates old withFunctionCallbackContext() methods in builders to guide
    migration
- Updates integration tests to use DefaultFunctionCallbackResolver
- Improves documentation to clarify the resolver's role in function callbacks
- Moves SchemaType enum from FunctionCallbackContext to FunctionCallback (Braking change)git add .

Resolves spring-projects#758
@tzolov tzolov force-pushed the issue-758-function-callback-resolver branch from 33c25ee to 30af292 Compare November 25, 2024 15:33
* @param beanName the name of the bean to resolve
* @return the {@link FunctionCallback} instance
*/
FunctionCallback getFunctionCallback(@NonNull String beanName, @Nullable String defaultDescription);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

FunctionCallback resolve(@NonNull String name)

The description should be provided by the implementation.

* @param functionCallbackContext the function callback context used to store the
* state of the function calls.
* @param functionCallbackResolver the function callback resolver used to resolve the
* function by bean name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc doesn't need to refer "bean" and just "by name" is enough. will fix when merging.

@ilayaperumalg
Copy link
Member

Fixed the javadoc, squashed, rebased and merged as 479a095

@ilayaperumalg
Copy link
Member

Also, fixed an issue with the AnthropicAutoConfiguration's AnthropicChatModel to use the interface dependent type FunctionCallbackResolver be0f9fb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor FunctionCallbackContext to FuctionCallBackResolver interface

3 participants